﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;
using KCurveAPI;

namespace Demo_KCurveAPI
{
  class Program
  {
    static public StockQuoteInterface m_sqi = new StockQuoteInterface();

    static int GetStockQuote(StockQuote sq)
    {
      if (m_sqi.Windcode == null)
      {
        m_sqi.Windcode = sq.Windcode;
      }

      if (sq.Windcode != m_sqi.Windcode)
        return 0;

      m_sqi.ShortName = sq.ShortName;
      m_sqi.CurrentDate = sq.CurrentDate;
      m_sqi.CurrentPrice = sq.CurrentPrice;
      m_sqi.Swing = sq.Swing;
      m_sqi.SwingPercent = sq.SwingPercent;
      m_sqi.IsDown = sq.IsDown;
      m_sqi.YestodayPrice = sq.YestodayPrice;
      m_sqi.QuoteDateList.Add(sq.CurrentDate);
      m_sqi.QuotePriceList.Add(Convert.ToDouble(sq.CurrentPrice));

      // 输出demo数据，顺序如下： wind_code, current_time, new_price, last_price
      Console.WriteLine("");
      Console.WriteLine(sq.Windcode);
      Console.WriteLine(sq.CurrentDate);
      Console.WriteLine(sq.CurrentPrice);
      Console.WriteLine(sq.YestodayPrice);

      return 0;
    }

    static void Main(string[] args)
    {
      KCurve kc = new KCurve(GetStockQuote);

      // 测试获取交易时间
      DateTime QuoteStartTime = new DateTime();
      DateTime PauseStartTime = new DateTime();
      DateTime PauseEndTime = new DateTime();
      DateTime QuoteEndTime = new DateTime();

      kc.GetQuoteTimeInfo(out QuoteStartTime, out PauseStartTime, out PauseEndTime, out QuoteEndTime);

      m_sqi.QuoteStartTime = QuoteStartTime;
      m_sqi.PauseStartTime = PauseStartTime;
      m_sqi.PauseEndTime = PauseEndTime;
      m_sqi.QuoteEndTime = QuoteEndTime;

      // 测试获取证券成交信息
      kc.work();
    }
  }
}
